/**
 * API接口映射配置
 * 确保前后端接口完全对接
 */

// 基础API配置
export const API_BASE_CONFIG = {
  // 基础URL
  BASE_URL: 'http://127.0.0.1:8000',
  
  // API版本
  API_VERSION: 'v1',
  
  // 超时时间
  TIMEOUT: 10000,
  
  // 重试次数
  RETRY_TIMES: 3,
  
  // 重试延迟
  RETRY_DELAY: 1000
}

// 接口路径映射
export const API_ENDPOINTS = {
  // 用户相关
  USER: {
    LOGIN: '/user/login',
    REGISTER: '/user/register',
    INFO: '/user/info',
    UPDATE: '/user/info',
    PASSWORD: '/user/password',
    FORGOT_PASSWORD: '/user/forgot-password',
    RESET_PASSWORD: '/user/reset-password',
    SEND_CODE: '/user/send-code',
    VERIFY_CODE: '/user/verify-code',
    LOGOUT: '/user/logout',
    STATS: '/user/stats',
    FAVORITES: '/user/favorites',
    FAVORITES_CHECK: '/user/favorites/check',
    WX_LOGIN_CONFIG: '/user/wx-login-config',
    WX_LOGIN: '/user/wx-login',
    BIND_WECHAT: '/user/bind-wechat',
    UNBIND_WECHAT: '/user/unbind-wechat'
  },

  // 商品相关
  GOODS: {
    LIST: '/goods/list',
    DETAIL: '/goods/detail',
    SEARCH: '/goods/search',
    HOT: '/goods/hot',
    RECOMMEND: '/goods/recommend',
    SPECIAL: '/goods/special',
    NEW: '/goods/new',
    EVALUATIONS: '/goods/evaluations',
    SPECS: '/goods/specs',
    STOCK: '/goods/stock',
    CATEGORIES: '/goods/categories',
    BANNERS: '/goods/banners'
  },

  // 订单相关
  ORDERS: {
    LIST: '/orders/list',
    DETAIL: '/orders/detail',
    CREATE: '/orders/create',
    CANCEL: '/orders/cancel',
    CONFIRM: '/orders/confirm',
    REFUND: '/orders/refund',
    PAY: '/orders/pay',
    STATS: '/orders/stats',
    LOGISTICS: '/orders/logistics',
    EVALUATE: '/orders/evaluate',
    DELETE: '/orders/delete',
    REBUY: '/orders/rebuy',
    INVOICE: '/orders/invoice'
  },

  // 购物车相关
  CART: {
    LIST: '/cart/list',
    ADD: '/cart/add',
    UPDATE: '/cart/update',
    REMOVE: '/cart/remove',
    CLEAR: '/cart/clear',
    BATCH_REMOVE: '/cart/batch-remove',
    SELECT: '/cart/select',
    SELECT_ALL: '/cart/select-all',
    STATS: '/cart/stats',
    CHECK: '/cart/check',
    RECOMMENDATIONS: '/cart/recommendations'
  },

  // 地址相关
  ADDRESS: {
    LIST: '/address/list',
    DETAIL: '/address/detail',
    ADD: '/address/add',
    UPDATE: '/address/update',
    DELETE: '/address/delete',
    SET_DEFAULT: '/address/set-default',
    DEFAULT: '/address/default',
    PROVINCES: '/address/provinces',
    CITIES: '/address/cities',
    DISTRICTS: '/address/districts',
    VALIDATE: '/address/validate'
  },

  // 优惠券相关
  COUPON: {
    LIST: '/coupon/list',
    MY_COUPONS: '/coupon/my',
    RECEIVE: '/coupon/receive',
    USE: '/coupon/use'
  },

  // 支付相关
  PAYMENT: {
    WECHAT_PAY: '/payment/wechat',
    ALIPAY: '/payment/alipay',
    QUERY: '/payment/query'
  },

  // 文件上传
  UPLOAD: {
    IMAGE: '/upload/image',
    FILE: '/upload/file'
  },

  // 其他
  COMMON: {
    BANNER: '/common/banner',
    CONFIG: '/common/config',
    FEEDBACK: '/common/feedback'
  }
}

// 参数映射规则
export const PARAM_MAPPING = {
  // 前端 -> 后端
  REQUEST: {
    pageSize: 'page_size',
    categoryId: 'category_id',
    goodsId: 'goods_id',
    specId: 'spec_id',
    orderId: 'order_id',
    addressId: 'address_id',
    userId: 'user_id',
    createTime: 'create_time',
    updateTime: 'update_time',
    goodsName: 'goods_name',
    specName: 'spec_name',
    retailPrice: 'retail_price',
    marketPrice: 'market_price',
    salesQuantity: 'sales_quantity',
    isDefault: 'is_default',
    receiverName: 'receiver_name',
    receiverPhone: 'receiver_phone',
    detailAddress: 'detail_address',
    postalCode: 'postal_code',
    addressTag: 'address_tag',
    paymentMethod: 'payment_method',
    shippingFee: 'shipping_fee',
    discountAmount: 'discount_amount',
    totalAmount: 'total_amount',
    finalAmount: 'final_amount',
    orderStatus: 'order_status',
    paymentStatus: 'payment_status',
    tradeNo: 'trade_no',
    customerName: 'customer_name',
    customerAvatar: 'customer_avatar',
    commentId: 'comment_id',
    replyContent: 'reply_content',
    brandName: 'brand_name',
    className: 'class_name',
    shortName: 'short_name',
    imgUrl: 'img_url',
    specBarcode: 'spec_barcode',
    originalPrice: 'original_price'
  },

  // 后端 -> 前端
  RESPONSE: {
    page_size: 'pageSize',
    category_id: 'categoryId',
    goods_id: 'goodsId',
    spec_id: 'specId',
    order_id: 'orderId',
    address_id: 'addressId',
    user_id: 'userId',
    create_time: 'createTime',
    update_time: 'updateTime',
    goods_name: 'goodsName',
    spec_name: 'specName',
    retail_price: 'retailPrice',
    market_price: 'marketPrice',
    sales_quantity: 'salesQuantity',
    is_default: 'isDefault',
    receiver_name: 'receiverName',
    receiver_phone: 'receiverPhone',
    detail_address: 'detailAddress',
    postal_code: 'postalCode',
    address_tag: 'addressTag',
    payment_method: 'paymentMethod',
    shipping_fee: 'shippingFee',
    discount_amount: 'discountAmount',
    total_amount: 'totalAmount',
    final_amount: 'finalAmount',
    order_status: 'orderStatus',
    payment_status: 'paymentStatus',
    trade_no: 'tradeNo',
    customer_name: 'customerName',
    customer_avatar: 'customerAvatar',
    comment_id: 'commentId',
    reply_content: 'replyContent',
    brand_name: 'brandName',
    class_name: 'className',
    short_name: 'shortName',
    img_url: 'imgUrl',
    spec_barcode: 'specBarcode',
    original_price: 'originalPrice'
  }
}

// 响应状态码映射
export const STATUS_CODE_MAPPING = {
  SUCCESS: 200,
  CREATED: 201,
  NO_CONTENT: 204,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  CONFLICT: 409,
  UNPROCESSABLE_ENTITY: 422,
  INTERNAL_SERVER_ERROR: 500,
  BAD_GATEWAY: 502,
  SERVICE_UNAVAILABLE: 503
}

// 错误消息映射
export const ERROR_MESSAGE_MAPPING = {
  NETWORK_ERROR: '网络连接失败，请检查网络设置',
  TIMEOUT_ERROR: '请求超时，请稍后重试',
  AUTH_ERROR: '登录已过期，请重新登录',
  PERMISSION_ERROR: '权限不足，无法执行此操作',
  PARAM_ERROR: '参数错误，请检查输入',
  SERVER_ERROR: '服务器错误，请稍后重试',
  UNKNOWN_ERROR: '未知错误，请稍后重试'
}

// 接口配置
export const API_CONFIG = {
  // 是否需要认证
  AUTH_REQUIRED: {
    '/user/info': true,
    '/user/update': true,
    '/user/password': true,
    '/user/logout': true,
    '/user/stats': true,
    '/user/favorites': true,
    '/cart/list': true,
    '/cart/add': true,
    '/cart/update': true,
    '/cart/remove': true,
    '/cart/clear': true,
    '/orders/list': true,
    '/orders/create': true,
    '/orders/cancel': true,
    '/orders/confirm': true,
    '/orders/pay': true,
    '/address/list': true,
    '/address/add': true,
    '/address/update': true,
    '/address/delete': true
  },

  // 缓存配置
  CACHE_CONFIG: {
    '/goods/categories': 3600000, // 1小时
    '/goods/banners': 1800000,    // 30分钟
    '/user/info': 300000,         // 5分钟
    '/address/provinces': 86400000 // 24小时
  },

  // 重试配置
  RETRY_CONFIG: {
    '/goods/list': 2,
    '/orders/list': 1,
    '/cart/list': 1
  }
}

// 导出默认配置
export default {
  API_BASE_CONFIG,
  API_ENDPOINTS,
  PARAM_MAPPING,
  STATUS_CODE_MAPPING,
  ERROR_MESSAGE_MAPPING,
  API_CONFIG
} 